﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SkladLib.ListViewSklad
{
    /// <summary>
    /// Interaction logic for userListViewSklad.xaml
    /// </summary>
    public partial class userListViewSklad : UserControl
    {
        public userListViewSklad()
        {
            InitializeComponent();
        }

        public void refresh()
        {
            DataLib.Settings.databases.dbSklad.loadAllSortTo("id", "sklad", lvSklad);
        }

        private void userListViewSklad_Loaded_1(object sender, RoutedEventArgs e)
        {
            lvSklad.IsEnabled = true;
            refresh();
        }

        private void lvSklad_Loaded_1(object sender, RoutedEventArgs e)
        {

        }

        private void ConMenuSmazat_Click_1(object sender, RoutedEventArgs e)
        {
            if (lvSklad.SelectedIndex != -1)
            {
                System.Data.DataRowView value = (System.Data.DataRowView)lvSklad.SelectedValue;
                DataLib.Settings.databases.dbSklad.DeleteRow("Sklad", "id", value.Row["id"].ToString());
                refresh();
            }
        }

        private void ConMenuDoSkladu_Click_1(object sender, RoutedEventArgs e)
        {
            if (lvSklad.SelectedIndex != -1)
            {
                System.Data.DataRowView value = (System.Data.DataRowView)lvSklad.SelectedValue;
                bool isNaSklade = !(bool)value["naSklade"];
                DataLib.Settings.databases.dbSklad.Query("UPDATE Sklad SET naSklade='" + isNaSklade + "' WHERE id='" + value["id"] + "'");
                refresh();
            }
        }


        private void conMenuSklad_Opened_1(object sender, RoutedEventArgs e)
        {
           /* if (lvSklad.Items.Count == 0)
                conMenuSklad.IsEnabled = false;
            else
                conMenuSklad.IsEnabled = true;*/
        }
    }
}
